package com.example.thesunofvn.smspro;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListViewAdapter extends ArrayAdapter<Smss> {
	 List<Smss> array;
	 int resource;
	 TextView tvAddress;
	 TextView tvBody;
	 Context context;
	 Smss mess;
	 View.OnTouchListener mTouchListener;
	public ListViewAdapter(Context context, 
			int textViewResourceId, List<Smss> array) {
		super(context, textViewResourceId, array);
		this.context = context;
		 this.resource = textViewResourceId;
		 this.array = array;
		// TODO Auto-generated constructor stub
	}
	public ListViewAdapter(Context context, 
			int textViewResourceId, List<Smss> array, View.OnTouchListener listener) {
		super(context, textViewResourceId, array);
		this.context = context;
		 this.resource = textViewResourceId;
		 this.array = array;
		 mTouchListener = listener;
		// TODO Auto-generated constructor stub
	}
	 public View getView(int position, View convertView, ViewGroup parent){
		 
		 View friendView = convertView;
		 if(friendView ==null ){
		 friendView = new CustomeListview(getContext());
		 friendView.setOnTouchListener(mTouchListener);
		 }
		 mess = array.get(position);
		 if(mess !=null){
			 tvAddress = ((CustomeListview)friendView).lbAddress;
			 tvBody = ((CustomeListview)friendView).lbBody;
		 // lay doi tuong friend va dua ra UI
		 tvAddress.setText(mess.getAddress());
		 tvBody.setText(mess.getSmss().get(0).getMsg());
		 }
		 return friendView;
		 }
	 @Override
	 public Smss getItem(int position) {
		 Smss mess=null;
		 if(array.size()>0&&position<array.size())
			 mess=array.get(position);
	     return mess;
	 }
 /*  @Override
	    public long getItemId(int position) {
	        String item = getItem(position).getPlaceid()+"";
	        return mIdMap.get(item);
	    }*/
	    @Override
	    public boolean hasStableIds() {
	        return true;
	    } 
	 public void removeItemAt(int position){
		 
		 array.remove(position);
	 }
}
